#include "../userprog/syscall.h"

void main(){

/*Variables used by the old setupMovieTheater() function*/
int i,r,c;
char* execName;
int nameLen;

/******************Pointer declarations*/


/*Global Data*/
int PRINT_DEBUG_MESSAGES;
int PRINT_OUTPUT_MESSAGES;
int PRINT_TEST_CASE_MESSAGES;
int ENABLE_BREAKS;
int latestIndex;
int latestIndexLock;
int latestIndexCondition;


/*Constants*/
/*Monetary Constants*/
int TICKET_PRICE;
int POPCORN_PRICE;
int SODA_PRICE;
/*Clerk Amounts*/
int NUM_TICKET_CLERKS;
int NUM_CONCESSION_CLERKS;
int NUM_TICKET_TAKERS;
/*Customer Amounts*/
int NUM_CUSTOMERS;
int NUM_GROUPS;
int MAX_GROUP_SIZE;
/*Customer Probability Constants*/
int CUSTOMER_WANT_POPCORN_PROBABILITY;
int CUSTOMER_WANT_SODA_PROBABILITY;
int CUSTOMER_WANT_BATHROOM_PROBABILITY;
/*Screening Room Properties*/
int SCREENING_ROOM_ROWS;
int SCREENING_ROOM_COLS;
int SCREENING_ROOM_CAPACITY;
/*Manager Probability Constants*/
int MANAGER_DELAY_ACCEPTING;
int MANAGER_ROLL_ACCEPT;
int MANAGER_YIELD_ACCEPTING;
int MANAGER_DELAY_CUTOFF;
int MANAGER_DELAY_PROFITS;
int MANAGER_DELAY_BREAK;
int MANAGER_ROLL_ONBREAK;
int MANAGER_LONGLINE;
int MANAGER_SHORTLINE;
/*Enums*/
/*Customer Initialization Modes*/
int CUSTOMER_INIT_MODE;
int CONSTANT_NUMBER_OF_CUSTOMERS, CONSTANT_NUMBER_OF_GROUPS;
/*Clerk States*/
int CLERK_ON_BREAK, CLERK_AVAILABLE, CLERK_BUSY;
/*Movie Process States*/
int MOVIE_STATE;
int ROOM_EMPTY, ACCEPTING_TICKETS, CUSTOMER_CUTOFF, IN_PROGRESS, ROOM_EMPTYING;




/*General Movie Theater Data*/
int numCustomersInTheater;
int numCustomersInTheaterLock;
int numGroupsInTheater;
int numGroupsInTheaterLock;
int totalTicketsSold;
int totalPopcornSold;
int totalSodaSold;
int ticketCountBox;
int ticketCountBoxLock;
int movieStateLock;
int movieNumber;
/*Special/Testing Data*/
int overrideExitCondition;
int overrideExitLock;
/*Screening Room Data*/
int screeningRoomSeat;
int screeningRoomRow;
int screeningRoomLock;
int movieInProgressLock;
int movieInProgressCondition;
/*Data, Locks and Conditions Controlling the Customers*/
int customerInitLock;
int customerInitCondition;
int customerStartLock;
int customerStartCondition;
/*Data, Locks and Conditions Controlling the TicketClerks*/
int tcLineLength;
int tcLineManager;
int tcInteractionLock;
int tcLineCondition;
int tcInteractionCondition;
int tcState;
int tcStateLock;
int tcStateCondition;
int numTicketsDesired;
/*Data, Locks and Conditions Controlling the ConcessionClerks*/
int ccLineLength;
int ccLineManager;
int ccInteractionLock;
int ccLineCondition;
int ccInteractionCondition;
int ccState;
int ccStateLock;
int ccStateCondition;
int numPopcornDesired;
int numSodaDesired;
/*Data, Locks and Conditions Controlling the TicketTakers*/
int ttLineManager;
int ticketTakerFullLock;
int ttStopLock;
int ttStopCondition;
int ttLineLength;
int ttInteractionLock;
int ttLineCondition;
int ttInteractionCondition;
int ttLobbyLock;
int ttLobbyCondition;
int ticketTakerFull;
int ticketTakerSaidToProceed;
int ttState;
int ttStateLock;
int ttStateCondition;
int numTicketsGiven;
int ttForcedToStop;
/*Data, Locks and Conditions Controlling the Manager*/
int profitLock;
int movieTechLock;
int movieTechCondition;
int tcsOnBreak;
int ccsOnBreak;
int ttsOnBreak;
int beginTakingTicketsLock;
int beginTakingTicketsCondition;
int tcBreakLock;
int tcBreakCondition;
int tcBreakStopLock;
int tcBreakStopCondition;
int ccBreakLock;
int ccBreakCondition;
int ccBreakStopLock;
int ccBreakStopCondition;
int ttBreakLock;
int ttBreakCondition;
int ttBreakStopLock;
int ttBreakStopCondition;

/*Set Constants & Global Data*/
PRINT_DEBUG_MESSAGES = CreateMV(1,"PRINT_DEBUG_MESSAGES",20);
SetMV(PRINT_DEBUG_MESSAGES, 0, 0);

PRINT_OUTPUT_MESSAGES = CreateMV(1,"PRINT_OUTPUT_MESSAGES", 21);
SetMV(PRINT_OUTPUT_MESSAGES, 0, 1);

PRINT_TEST_CASE_MESSAGES = CreateMV(1, "PRINT_TEST_CASE_MESSAGES", 24);
SetMV(PRINT_TEST_CASE_MESSAGES, 0, 0);

ENABLE_BREAKS = CreateMV(1, "ENABLE_BREAKS", 13);
SetMV(ENABLE_BREAKS, 0, 0);


/******************MV setting /Array Creation*/

/*Constants*/
/*Monetary Constants*/
TICKET_PRICE = CreateMV(1,"TICKET_PRICE", 12);
SetMV(TICKET_PRICE, 0, 12);

POPCORN_PRICE = CreateMV(1,"POPCORN_PRICE", 13);
SetMV(POPCORN_PRICE, 0, 5);

SODA_PRICE = CreateMV(1,"SODA_PRICE", 10);
SetMV(SODA_PRICE,0,4);
/*Clerk Amounts*/
NUM_TICKET_CLERKS = CreateMV(1, "NUM_TICKET_CLERKS", 17);
SetMV(NUM_TICKET_CLERKS, 0, 5);

NUM_CONCESSION_CLERKS = CreateMV(1, "NUM_CONCESSION_CLERKS", 21);
SetMV(NUM_CONCESSION_CLERKS, 0, 5);

NUM_TICKET_TAKERS = CreateMV(1, "NUM_TICKET_TAKERS", 17);
SetMV(NUM_TICKET_TAKERS, 0, 3);
/*Customer Amounts*/
NUM_CUSTOMERS = CreateMV(1, "NUM_CUSTOMERS", 13);
SetMV(NUM_CUSTOMERS, 0, 40);

NUM_GROUPS = CreateMV(1, "NUM_GROUPS", 10);
SetMV(NUM_GROUPS, 0, 20);

MAX_GROUP_SIZE = CreateMV(1, "MAX_GROUP_SIZE", 14);
SetMV(MAX_GROUP_SIZE, 0 , 5);
/*Customer Probability Constants*/
CUSTOMER_WANT_POPCORN_PROBABILITY = CreateMV(1, "CUSTOMER_WANT_POPCORN_PROBABILITY", 33);
SetMV(CUSTOMER_WANT_POPCORN_PROBABILITY, 0 ,75);

CUSTOMER_WANT_SODA_PROBABILITY = CreateMV(1, "CUSTOMER_WANT_SODA_PROBABILITY", 30);
SetMV(CUSTOMER_WANT_SODA_PROBABILITY,0,75);

CUSTOMER_WANT_BATHROOM_PROBABILITY = CreateMV(1, "CUSTOMER_WANT_BATHROOM_PROBABILITY", 34);
SetMV(CUSTOMER_WANT_BATHROOM_PROBABILITY, 0, 25);
/*Screening Room Properties*/
SCREENING_ROOM_ROWS = CreateMV(1,"SCREENING_ROOM_ROWS",19);
SetMV(SCREENING_ROOM_ROWS, 0, 5);

SCREENING_ROOM_COLS = CreateMV(1,"SCREENING_ROOM_COLS", 19);
SetMV(SCREENING_ROOM_COLS, 0, 5);

SCREENING_ROOM_CAPACITY = CreateMV(1, "SCREENING_ROOM_CAPACITY", 23);
SetMV(SCREENING_ROOM_CAPACITY, 0, 25);
/*Manager Probability Constants*/
MANAGER_DELAY_ACCEPTING = CreateMV(1, "MANAGER_DELAY_ACCEPTING", 23);
SetMV(MANAGER_DELAY_ACCEPTING, 0, 1);

MANAGER_ROLL_ACCEPT = CreateMV(1, "MANAGER_ROLL_ACCEPT", 19);
SetMV(MANAGER_ROLL_ACCEPT,0,50);

MANAGER_YIELD_ACCEPTING = CreateMV(1,"MANAGER_YIELD_ACCEPTING", 23);
SetMV(MANAGER_YIELD_ACCEPTING, 0 , 15);

MANAGER_DELAY_CUTOFF = CreateMV(1, "MANAGER_DELAY_CUTOFF",20);
SetMV(MANAGER_DELAY_CUTOFF,0,1);

MANAGER_DELAY_PROFITS = CreateMV(1,"MANAGER_DELAY_PROFITS",21);
SetMV(MANAGER_DELAY_PROFITS,0,5);

MANAGER_DELAY_BREAK = CreateMV(1,"MANAGER_DELAY_BREAK",19);
SetMV(MANAGER_DELAY_BREAK,0,1);

MANAGER_ROLL_ONBREAK = CreateMV(1,"MANAGER_ROLL_ONBREAK", 20);
SetMV(MANAGER_ROLL_ONBREAK,0,20);

MANAGER_LONGLINE = CreateMV(1,"MANAGER_LONGLINE",16);
SetMV(MANAGER_LONGLINE,0,5);

MANAGER_SHORTLINE = CreateMV(1,"MANAGER_SHORTLINE",17);
SetMV(MANAGER_SHORTLINE,0,3);
/*Enums*/
/*Customer Initialization Modes*/
CUSTOMER_INIT_MODE = CreateMV(1, "CUSTOMER_INIT_MODE",18);

CONSTANT_NUMBER_OF_CUSTOMERS = CreateMV(1,"CONSTANT_NUMBER_OF_CUSTOMERS",28);
SetMV(CONSTANT_NUMBER_OF_CUSTOMERS,0,0);

CONSTANT_NUMBER_OF_GROUPS = CreateMV(1,"CONSTANT_NUMBER_OF_GROUPS",25);
SetMV(CONSTANT_NUMBER_OF_GROUPS,0,1);
/*Clerk States*/
CLERK_ON_BREAK = CreateMV(1,"CLERK_ON_BREAK",14);
SetMV(CLERK_ON_BREAK,0,-1);

CLERK_AVAILABLE = CreateMV(1,"CLERK_AVAILABLE",15);
SetMV(CLERK_AVAILABLE,0,0);

CLERK_BUSY = CreateMV(1,"CLERK_BUSY",10);
SetMV(CLERK_BUSY,0,1);

/*Movie Process States*/
MOVIE_STATE = CreateMV(1,"MOVIE_STATE",11);

ROOM_EMPTY = CreateMV(1,"ROOM_EMPTY",10);
SetMV(ROOM_EMPTY,0,0);

ACCEPTING_TICKETS = CreateMV(1,"ACCEPTING_TICKETS",17);
SetMV(ACCEPTING_TICKETS,0,1);

CUSTOMER_CUTOFF = CreateMV(1,"CUSTOMER_CUTOFF",15);
SetMV(CUSTOMER_CUTOFF, 0, 2);

IN_PROGRESS = CreateMV(1,"IN_PROGRESS",11);
SetMV(IN_PROGRESS,0,3);

ROOM_EMPTYING = CreateMV(1,"ROOM_EMPTYING",13);
SetMV(ROOM_EMPTYING,0,4);
/*General Movie Theater Data*/
numCustomersInTheater = CreateMV(1,"numCustomersInTheater",21);
numGroupsInTheater = CreateMV(1,"numGroupsInTheater",18);
totalTicketsSold = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"totalTicketsSold",16);
totalPopcornSold = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"totalPopcornSold",16);
totalSodaSold = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"totalSodaSold",13);
ticketCountBox = CreateMV(1,"ticketCountBox",14);
movieNumber = CreateMV(1,"movieNumber",11);
/*Special/Testing Data*/
/*Screening Room Data*/
screeningRoomSeat = CreateMV(GetMV(SCREENING_ROOM_ROWS,0),"screeningRoomSeat",17);
screeningRoomRow = CreateMV(GetMV(SCREENING_ROOM_COLS,0),"screeningRoomRow",16);
/*Data, Locks and Conditions Controlling the Customers*/
/*Data, Locks and Conditions Controlling the TicketClerks*/
tcLineLength = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcLineLength",12);
tcInteractionLock = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcInteractionLock",17);
tcLineCondition = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcLineCondition",15);
tcInteractionCondition = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcInteractionCondition",22);
tcState = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcState",7);
tcStateLock = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcStateLock",11);
tcStateCondition = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcStateCondition",16);
numTicketsDesired = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"numTicketsDesired",17);
/*Data, Locks and Conditions Controlling the ConcessionClerks*/
ccLineLength = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccLineLength",12);
ccInteractionLock = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccInteractionLock",17);
ccLineCondition = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccLineCondition",15);
ccInteractionCondition = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccInteractionCondition",22);
ccState = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccState",7);
ccStateLock = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccStateLock",11);
ccStateCondition = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccStateCondition",16);
numPopcornDesired = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"numPopcornDesired",17);
numSodaDesired = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"numSodaDesired",14);
/*Data, Locks and Conditions Controlling the TicketTakers*/
ttLineLength = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttLineLength",12);
ttInteractionLock = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttInteractionLock",17);
ttLineCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttLineCondition",15);
ttInteractionCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttInteractionCondition",22);
ttState = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttState",7);
ttStateLock = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttStateLock",11);
ttStateCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttStateCondition",16);
ttLobbyLock = CreateMV(GetMV(NUM_TICKET_TAKERS,0)+1,"ttLobbyLock",11);
ttLobbyCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0)+1,"ttLobbyCondition",16);
ticketTakerFull = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ticketTakerFull",15);
ticketTakerSaidToProceed = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ticketTakerSaidToProceed",24);
numTicketsGiven = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"numTicketsGiven",15);
ttForcedToStop = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttForcedToStop",14);
/*Data, Locks and Conditions Controlling the Manager*/
tcsOnBreak = CreateMV(1,"tcsOnBreak",10);
ccsOnBreak = CreateMV(1,"ccsOnBreak",10);
ttsOnBreak = CreateMV(1,"ttsOnBreak",10);
beginTakingTicketsLock = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"beginTakingTicketsLock",22);
beginTakingTicketsCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"beginTakingTicketsCondition",27);
tcBreakLock = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcBreakLock",11);
tcBreakCondition = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcBreakCondition",16);
tcBreakStopLock = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcBreakStopLock",15);
tcBreakStopCondition = CreateMV(GetMV(NUM_TICKET_CLERKS,0),"tcBreakStopCondition",20);
ccBreakLock = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccBreakLock",11);
ccBreakCondition = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccBreakCondition",16);
ccBreakStopLock = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccBreakStopLock",15);
ccBreakStopCondition = CreateMV(GetMV(NUM_CONCESSION_CLERKS,0),"ccBreakStopCondition",20);
ttBreakLock = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttBreakLock",11);
ttBreakCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttBreakCondition",16);
ttBreakStopLock = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttBreakStopLock",15);
ttBreakStopCondition = CreateMV(GetMV(NUM_TICKET_TAKERS,0),"ttBreakStopCondition",20);


/*Set Up Movie Theater (lock/condition creation, array initialization)*/
SetMV(MOVIE_STATE,0,GetMV(ROOM_EMPTY,0));
SetMV(CUSTOMER_INIT_MODE,0,GetMV(CONSTANT_NUMBER_OF_GROUPS,0));
SetMV(latestIndex,0,0);
latestIndexLock = CreateLock("latestIndexLock",15);
latestIndexCondition = CreateCondition("latestIndexCondition",20);
tcLineManager = CreateLock("tcLineManager",13);

if(GetMV(PRINT_DEBUG_MESSAGES,0)) FPrint("Setting up movie theater...\n", 29, 0, 0);
SetMV(numCustomersInTheater,0,0);
numCustomersInTheaterLock = CreateLock("numCustomersInTheaterLock",25);
SetMV(numGroupsInTheater,0,0);
numGroupsInTheaterLock = CreateLock("numGroupsInTheaterLock",22);
SetMV(ticketCountBox,0,0);
ticketCountBoxLock = CreateLock("ticketCountBoxLock",18);
movieStateLock = CreateLock("movieStateLock",14);
SetMV(movieNumber,0,0);
overrideExitCondition = CreateCondition("overrideExitCondition",21);
overrideExitLock = CreateLock("overrideExitLock",16);

/*Hack since the number of rows is essentially hardcoded*/
/*Correct way would be to loop and generate a unique name for each newly created MV using the row number*/
SetMV(screeningRoomSeat,0,CreateMV(GetMV(SCREENING_ROOM_COLS,0),"ScreeningRoomRow0",17));
SetMV(screeningRoomSeat,1,CreateMV(GetMV(SCREENING_ROOM_COLS,0),"ScreeningRoomRow1",17));
SetMV(screeningRoomSeat,2,CreateMV(GetMV(SCREENING_ROOM_COLS,0),"ScreeningRoomRow2",17));
SetMV(screeningRoomSeat,3,CreateMV(GetMV(SCREENING_ROOM_COLS,0),"ScreeningRoomRow3",17));
SetMV(screeningRoomSeat,4,CreateMV(GetMV(SCREENING_ROOM_COLS,0),"ScreeningRoomRow4",17));

for(r = 0; r < GetMV(SCREENING_ROOM_ROWS,0); r++)
{	
	for(c = 0; c < GetMV(SCREENING_ROOM_COLS,0); c++)
	{
		SetMV(GetMV(screeningRoomSeat, r), c, -1);
	}
}

screeningRoomLock = CreateLock("screeningRoomLock",17);
movieInProgressLock = CreateLock("movieInProgressLock",19);
movieInProgressCondition = CreateCondition("movieInProgressCondition",24);


customerInitLock = CreateLock("customerInitLock",16);
customerInitCondition = CreateCondition("customerInitCondition",21);
customerStartLock = CreateLock("customerStartLock",17);
customerStartCondition = CreateCondition("customerStartCondition",22);

ccLineManager = CreateLock("ccLineManager",13);

ttLineManager = CreateLock("ttLineManager",13);
ticketTakerFullLock = CreateLock("ticketTakerFullLock",19);
ttStopCondition = CreateCondition("ttStopCondition",15);
ttStopLock = CreateLock("ttStopLock",10);

profitLock = CreateLock("profitLock",10);

SetMV(tcsOnBreak,0,0);
SetMV(ccsOnBreak,0,0);
SetMV(ttsOnBreak,0,0);

movieTechLock = CreateLock("movieTechLock",13);
movieTechCondition = CreateCondition("movieTechCondition",18);


/*Hack since number of ticket clerks is essentially hardcoded*/
/*Correct way would be to loop and generate a unique name for each newly created MV using the tc index*/
SetMV(tcInteractionLock,0,CreateLock("tcInteractionLock0",18));
SetMV(tcLineCondition,0,CreateCondition("tcLineCondition0",16));
SetMV(tcInteractionCondition,0,CreateCondition("tcInteractionCondition0",23));
SetMV(tcStateLock,0,CreateLock("tcStateLock0",12));
SetMV(tcStateCondition,0,CreateCondition("tcStateCondition0",17));
SetMV(tcBreakLock,0,CreateLock("tcBreakLock0",12));
SetMV(tcBreakCondition,0,CreateCondition("tcBreakCondition0",17));
SetMV(tcBreakStopLock,0,CreateLock("tcBreakStopLock0",16));
SetMV(tcBreakStopCondition,0,CreateCondition("tcBreakStopCondition0",21));

SetMV(tcInteractionLock,1,CreateLock("tcInteractionLock1",18));
SetMV(tcLineCondition,1,CreateCondition("tcLineCondition1",16));
SetMV(tcInteractionCondition,1,CreateCondition("tcInteractionCondition1",23));
SetMV(tcStateLock,1,CreateLock("tcStateLock1",12));
SetMV(tcStateCondition,1,CreateCondition("tcStateCondition1",17));
SetMV(tcBreakLock,1,CreateLock("tcBreakLock1",12));
SetMV(tcBreakCondition,1,CreateCondition("tcBreakCondition1",17));
SetMV(tcBreakStopLock,1,CreateLock("tcBreakStopLock1",16));
SetMV(tcBreakStopCondition,1,CreateCondition("tcBreakStopCondition1",21));

SetMV(tcInteractionLock,2,CreateLock("tcInteractionLock2",18));
SetMV(tcLineCondition,2,CreateCondition("tcLineCondition2",16));
SetMV(tcInteractionCondition,2,CreateCondition("tcInteractionCondition2",23));
SetMV(tcStateLock,2,CreateLock("tcStateLock2",12));
SetMV(tcStateCondition,2,CreateCondition("tcStateCondition2",17));
SetMV(tcBreakLock,2,CreateLock("tcBreakLock2",12));
SetMV(tcBreakCondition,2,CreateCondition("tcBreakCondition2",17));
SetMV(tcBreakStopLock,2,CreateLock("tcBreakStopLock2",16));
SetMV(tcBreakStopCondition,2,CreateCondition("tcBreakStopCondition2",21));

SetMV(tcInteractionLock,3,CreateLock("tcInteractionLock3",18));
SetMV(tcLineCondition,3,CreateCondition("tcLineCondition3",16));
SetMV(tcInteractionCondition,3,CreateCondition("tcInteractionCondition3",23));
SetMV(tcStateLock,3,CreateLock("tcStateLock3",12));
SetMV(tcStateCondition,3,CreateCondition("tcStateCondition3",17));
SetMV(tcBreakLock,3,CreateLock("tcBreakLock3",12));
SetMV(tcBreakCondition,3,CreateCondition("tcBreakCondition3",17));
SetMV(tcBreakStopLock,3,CreateLock("tcBreakStopLock3",16));
SetMV(tcBreakStopCondition,3,CreateCondition("tcBreakStopCondition3",21));

SetMV(tcInteractionLock,4,CreateLock("tcInteractionLock4",18));
SetMV(tcLineCondition,4,CreateCondition("tcLineCondition4",16));
SetMV(tcInteractionCondition,4,CreateCondition("tcInteractionCondition4",23));
SetMV(tcStateLock,4,CreateLock("tcStateLock4",12));
SetMV(tcStateCondition,4,CreateCondition("tcStateCondition4",17));
SetMV(tcBreakLock,4,CreateLock("tcBreakLock4",12));
SetMV(tcBreakCondition,4,CreateCondition("tcBreakCondition4",17));
SetMV(tcBreakStopLock,4,CreateLock("tcBreakStopLock4",16));
SetMV(tcBreakStopCondition,4,CreateCondition("tcBreakStopCondition4",21));

for(i = 0; i < GetMV(NUM_TICKET_CLERKS,0); i++)
{
SetMV(totalTicketsSold,i,0);
SetMV(tcLineLength,i,0);
SetMV(tcState,i,GetMV(CLERK_AVAILABLE,0));
SetMV(numTicketsDesired,i,0);
}

/*Hack since the number of Concession Clerks is essentiall hardcoded*/
/*Correct way would be to loop and generate a unique name for each newly created MV using the cc index*/
SetMV(ccInteractionLock,0,CreateLock("ccInteractionLock0",18));
SetMV(ccLineCondition,0,CreateCondition("ccLineCondition0",16));
SetMV(ccInteractionCondition,0,CreateCondition("ccInteractionCondition0",23));
SetMV(ccStateLock,0,CreateLock("ccStateLock0",12));
SetMV(ccStateCondition,0,CreateCondition("ccStateCondition0",17));
SetMV(ccBreakLock,0,CreateLock("ccBreakLock0",12));
SetMV(ccBreakCondition,0,CreateCondition("ccBreakCondition0",17));
SetMV(ccBreakStopLock,0,CreateLock("ccBreakStopLock0",16));
SetMV(ccBreakStopCondition,0,CreateCondition("ccBreakStopCondition0",21));

SetMV(ccInteractionLock,1,CreateLock("ccInteractionLock1",18));
SetMV(ccLineCondition,1,CreateCondition("ccLineCondition1",16));
SetMV(ccInteractionCondition,1,CreateCondition("ccInteractionCondition1",23));
SetMV(ccStateLock,1,CreateLock("ccStateLock1",12));
SetMV(ccStateCondition,1,CreateCondition("ccStateCondition1",17));
SetMV(ccBreakLock,1,CreateLock("ccBreakLock1",12));
SetMV(ccBreakCondition,1,CreateCondition("ccBreakCondition1",17));
SetMV(ccBreakStopLock,1,CreateLock("ccBreakStopLock1",16));
SetMV(ccBreakStopCondition,1,CreateCondition("ccBreakStopCondition1",21));

SetMV(ccInteractionLock,2,CreateLock("ccInteractionLock2",18));
SetMV(ccLineCondition,2,CreateCondition("ccLineCondition2",16));
SetMV(ccInteractionCondition,2,CreateCondition("ccInteractionCondition2",23));
SetMV(ccStateLock,2,CreateLock("ccStateLock2",12));
SetMV(ccStateCondition,2,CreateCondition("ccStateCondition2",17));
SetMV(ccBreakLock,2,CreateLock("ccBreakLock2",12));
SetMV(ccBreakCondition,2,CreateCondition("ccBreakCondition2",17));
SetMV(ccBreakStopLock,2,CreateLock("ccBreakStopLock2",16));
SetMV(ccBreakStopCondition,2,CreateCondition("ccBreakStopCondition2",21));

SetMV(ccInteractionLock,3,CreateLock("ccInteractionLock3",18));
SetMV(ccLineCondition,3,CreateCondition("ccLineCondition3",16));
SetMV(ccInteractionCondition,3,CreateCondition("ccInteractionCondition3",23));
SetMV(ccStateLock,3,CreateLock("ccStateLock3",12));
SetMV(ccStateCondition,3,CreateCondition("ccStateCondition3",17));
SetMV(ccBreakLock,3,CreateLock("ccBreakLock3",12));
SetMV(ccBreakCondition,3,CreateCondition("ccBreakCondition3",17));
SetMV(ccBreakStopLock,3,CreateLock("ccBreakStopLock3",16));
SetMV(ccBreakStopCondition,3,CreateCondition("ccBreakStopCondition3",21));

SetMV(ccInteractionLock,4,CreateLock("ccInteractionLock4",18));
SetMV(ccLineCondition,4,CreateCondition("ccLineCondition4",16));
SetMV(ccInteractionCondition,4,CreateCondition("ccInteractionCondition4",23));
SetMV(ccStateLock,4,CreateLock("ccStateLock4",12));
SetMV(ccStateCondition,4,CreateCondition("ccStateCondition4",17));
SetMV(ccBreakLock,4,CreateLock("ccBreakLock4",12));
SetMV(ccBreakCondition,4,CreateCondition("ccBreakCondition4",17));
SetMV(ccBreakStopLock,4,CreateLock("ccBreakStopLock4",16));
SetMV(ccBreakStopCondition,4,CreateCondition("ccBreakStopCondition4",21));

for(i = 0; i < GetMV(NUM_CONCESSION_CLERKS,0); i++){
SetMV(totalPopcornSold,i,0);
SetMV(totalSodaSold,i,0);
SetMV(ccLineLength,i,0);
SetMV(ccState,i,GetMV(CLERK_AVAILABLE,0));
SetMV(numPopcornDesired,i,0);
SetMV(numSodaDesired,i,0);
}

/*Hack since the number of Concession Clerks is essentially hardcoded*/
/*Correct way would be to loop and generate a unique name for each newly created MV using the tt index*/
SetMV(ttInteractionLock,0,CreateLock("ttInteractionLock0",18));
SetMV(ttLineCondition,0,CreateCondition("ttLineCondition0",16));
SetMV(ttInteractionCondition,0,CreateCondition("ttInteractionCondition0",23));
SetMV(ttStateLock,0,CreateLock("ttStateLock0",12));
SetMV(ttStateCondition,0,CreateCondition("ttStateCondition0",17));
SetMV(ttBreakLock,0,CreateLock("ttBreakLock0",12));
SetMV(ttBreakCondition,0,CreateCondition("ttBreakCondition0",17));
SetMV(ttBreakStopLock,0,CreateLock("ttBreakStopLock0",16));
SetMV(ttBreakStopCondition,0,CreateCondition("ttBreakStopCondition0",21));

SetMV(ttInteractionLock,1,CreateLock("ttInteractionLock1",18));
SetMV(ttLineCondition,1,CreateCondition("ttLineCondition1",16));
SetMV(ttInteractionCondition,1,CreateCondition("ttInteractionCondition1",23));
SetMV(ttStateLock,1,CreateLock("ttStateLock1",12));
SetMV(ttStateCondition,1,CreateCondition("ttStateCondition1",17));
SetMV(ttBreakLock,1,CreateLock("ttBreakLock1",12));
SetMV(ttBreakCondition,1,CreateCondition("ttBreakCondition1",17));
SetMV(ttBreakStopLock,1,CreateLock("ttBreakStopLock1",16));
SetMV(ttBreakStopCondition,1,CreateCondition("ttBreakStopCondition1",21));

SetMV(ttInteractionLock,2,CreateLock("ttInteractionLock2",18));
SetMV(ttLineCondition,2,CreateCondition("ttLineCondition2",16));
SetMV(ttInteractionCondition,2,CreateCondition("ttInteractionCondition2",23));
SetMV(ttStateLock,2,CreateLock("ttStateLock2",12));
SetMV(ttStateCondition,2,CreateCondition("ttStateCondition2",17));
SetMV(ttBreakLock,2,CreateLock("ttBreakLock2",12));
SetMV(ttBreakCondition,2,CreateCondition("ttBreakCondition2",17));
SetMV(ttBreakStopLock,2,CreateLock("ttBreakStopLock2",16));
SetMV(ttBreakStopCondition,2,CreateCondition("ttBreakStopCondition2",21));

SetMV(ttLobbyLock,0,CreateLock("ttLobbyLock0",12));
SetMV(ttLobbyCondition,0,CreateCondition("ttLobbyCondition0",17));

SetMV(ttLobbyLock,1,CreateLock("ttLobbyLock1",12));
SetMV(ttLobbyCondition,1,CreateCondition("ttLobbyCondition1",17));

SetMV(ttLobbyLock,2,CreateLock("ttLobbyLock2",12));
SetMV(ttLobbyCondition,2,CreateCondition("ttLobbyCondition2",17));

SetMV(ttLobbyLock,3,CreateLock("ttLobbyLock3",12));
SetMV(ttLobbyCondition,3,CreateCondition("ttLobbyCondition3",17));

for(i = 0; i < GetMV(NUM_TICKET_TAKERS,0); i++){
SetMV(ttLineLength,i,0);
SetMV(ticketTakerFull,i,1);
SetMV(ticketTakerSaidToProceed,i,0);
SetMV(ttState,i,GetMV(CLERK_AVAILABLE,0));
SetMV(numTicketsGiven,i,0);
SetMV(ttForcedToStop,i,0);
}

/*Hack since the number of Concession Clerks is essentiall hardcoded*/
/*Correct way would be to loop and generate a unique name for each newly created MV using the tt index*/
SetMV(beginTakingTicketsLock,0,CreateLock("beginTakingTicketsLock0",23));
SetMV(beginTakingTicketsCondition,0,CreateCondition("beginTakingTicketsCondition0",28));

SetMV(beginTakingTicketsLock,1,CreateLock("beginTakingTicketsLock1",23));
SetMV(beginTakingTicketsCondition,1,CreateCondition("beginTakingTicketsCondition1",28));

SetMV(beginTakingTicketsLock,2,CreateLock("beginTakingTicketsLock2",23));
SetMV(beginTakingTicketsCondition,2,CreateCondition("beginTakingTicketsCondition2",28));


/*Exec everything*/
/*
if(GetMV(CUSTOMER_INIT_MODE,0)== GetMV(CONSTANT_NUMBER_OF_GROUPS,0))
{
	for(SetMV(latestIndex,0,0); GetMV(latestIndex,0) < GetMV(NUM_GROUPS,0); SetMV(latestIndex,0,GetMV(latestIndex,0) + 1))
	{
		AcquireLock(customerInitLock);

		execName = "../test/customer";
		nameLen = 16;
		Exec(execName, nameLen);
		
		WaitCondition(customerInitCondition, customerInitLock);
		AcquireLock(customerStartLock);
		ReleaseLock(customerStartLock);
		ReleaseLock(customerInitLock);
	}
	
	SetMV(NUM_CUSTOMERS,0,GetMV(numCustomersInTheater,0));
}

execName = "../test/movietech";
nameLen = 17;
Exec(execName, nameLen);

for(SetMV(latestIndex,0,0); GetMV(latestIndex,0) < GetMV(NUM_TICKET_CLERKS,0); SetMV(latestIndex,0,GetMV(latestIndex,0) + 1))
{
	AcquireLock(latestIndexLock);

	execName = "../test/ticketclerk";
	nameLen = 19;
	Exec(execName, nameLen);
	WaitCondition(latestIndexCondition, latestIndexLock);
	ReleaseLock(latestIndexLock);
}

for(SetMV(latestIndex,0,0); GetMV(latestIndex,0) < GetMV(NUM_CONCESSION_CLERKS,0); SetMV(latestIndex,0,GetMV(latestIndex,0) + 1))
{
	AcquireLock(latestIndexLock);
	execName = "../test/concessionclerk";
	nameLen = 23;
	Exec(execName, nameLen);
	
	WaitCondition(latestIndexCondition, latestIndexLock);
	ReleaseLock(latestIndexLock);

}

for(SetMV(latestIndex,0,0); GetMV(latestIndex,0) < GetMV(NUM_TICKET_TAKERS,0); SetMV(latestIndex,0,GetMV(latestIndex,0) + 1))
{
	AcquireLock(latestIndexLock);
	execName = "../test/tickettaker";
	nameLen = 19;
	Exec(execName, nameLen);
	WaitCondition(latestIndexCondition, latestIndexLock);
	ReleaseLock(latestIndexLock);
}

execName = "../test/manager";
nameLen = 15;
Exec(execName, nameLen);

*/

/*Launch Customers*/
/*
AcquireLock(customerStartLock);
BroadcastCondition(customerStartCondition, customerStartLock);
ReleaseLock(customerStartLock);
*/
}